const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}


// 获取歌词
function getLyric(id, callback){
  wx.request({
    url: "https://route.showapi.com/213-2",
    data:{
      musicid:id,
      showapi_appid: '53458',
      showapi_timestamp: new Date().getTime(),
      showapi_sign: '7cb1f2740ad14a3c9b7adbfdb12d5e26'
    },
    header:{
      'content-type': 'application/x-www-form-urlencoded'
    },
    success:function(res){
      if(res.statusCode == 200){
        callback(res.data)
      }
    }
  });
}

module.exports = {
  formatTime: formatTime,
  getLyric: getLyric
}
